<?php

use backend\assets\AppAsset;

use yii\helpers\Html;
use yii\helpers\Url;

use common\core\HoComm;

AppAsset::register($this);

?>

<?php $this->beginPage() ?>

<html>
<head>
    <meta charset="utf-8"/>
    <title>绿城后台管理</title>
    <?php $this->head() ?>
    <?php $this->endBody() ?>
    <?php $this->endPage() ?>
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <link href="css/jqvmap.css" rel="stylesheet" type="text/css" media="screen"/>
    <link href="css/jquery.easy-pie-chart.css" rel="stylesheet" type="text/css" media="screen"/>
    <link rel="shortcut icon" href="image/favicon.ico"/>
    <style type="text/css">
        .header .nav > li.dropdown .dropdown-toggle {
            padding: 0;
            height: 62px;
            box-sizing: border-box;
            line-height: 62px;
        }

        .header .nav > li.dropdown.user .dropdown-toggle {
            padding: 0;
            background-color: #fff;
            margin: 11px 6px;
            height: 40px;
            line-height: 40px;
            width: 76px;
            text-align: left;
            -webkit-border-radius: 20px;
            -moz-border-radius: 20px;
            -ms-border-radius: 2px;
            -o-border-radius: 20px;
            border-radius: 20px;
        }

        .header .nav > li.dropdown.user .dropdown-toggle img {
            width: 40px;
            height: 40px;
            -webkit-border-radius: 20px;
            -moz-border-radius: 20px;
            -ms-border-radius: 20px;
            -o-border-radius: 20px;
            border-radius: 20px;
        }
    </style>
</head>

<body class="page-header-fixed">
<div class="header navbar navbar-inverse navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container-fluid">
      <span>
        <a class="brand" style="padding:5px 0;" href="index.html"> <img style="height:54px" src="image/logo.png" alt="logo"/> </a>
        <span style="color: #ffffff;font-size:24px;line-height:62px;font-family:'Microsoft YaHei' ;">绿粉汇后台管理系统</span>
      </span>

            <ul class="nav pull-right">
                <li class="dropdown" id="header_notification_bar"><a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span><?= date("Y年m月d日", time()) ?>  <?= Yii::$app->user->identity->username ?>, 您好！</span> </a>
                </li>
                <li class="dropdown user">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <img alt="" src="image/avatar1_small.jpg" style="vertical-align: top;margin-right:8px;"/>
                        <span class="username"><?= Yii::$app->session['username'] ?></span>
                        <i class="icon-angle-down"></i>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a onclick="main_set_info_zfy()" href="#"><i class="icon-user"></i> 个人信息</a></li>
                        <li><a onclick="main_set_pwd_zfy()" href="#"><i class="icon-key"></i>编辑密码</a></li>
                        <li><a href="#" onclick="main_layout()"><i class="icon-lock"></i> 退出登录</a></li>
                    </ul>
                </li>

            </ul>
        </div>
    </div>
</div>

<div class="page-container">
    <div class="page-sidebar nav-collapse collapse">
        <ul class="page-sidebar-menu">
            <li>
                <div class="sidebar-toggler hidden-phone"></div>
            </li>
            <li id="site">
                <?php //if(Yii::$app->user->identity['level']==3){?>
                <a href="<?= Url::to(['site/index']) ?>">
                    <i class="icon-home"></i> <span class="title">首页</span> <span class="arrow "></span> </a>
            </li>
            <?php
            $menus = HoComm::getMenu();
            var_dump($menus);
            foreach ($menus as $key => $menu):

            ?>
            <li id="<?= $key ?>">
                <a href="javascript:;"> <i class="<?= HoComm::getCoin($key) ?>"></i>
                    <span class="title"><?= HoComm::getDescription($key) ?></span>
                    <span class="arrow "></span>
                </a>
                <?php if (!empty($menu)): ?>
                    <ul class="sub-menu">
                        <?php foreach ($menu as $m): ?>
                            <li class="" id="<?= $str = str_replace(['/', '&', '='], '', $m); ?>">
                                <a href="/index.php?r=/<?= $m ?>"> <?= HoComm::getDescription($m) ?> </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
            <?php endforeach; ?>
        </ul>
    </div>

    <div class="page-content">
        <div class="container-fluid">
            <?= $content; ?>
        </div>
    </div>
</div>
<div id="mian_layout_Modal" class="modal hide fade">
    <?php
    echo Html::beginForm(['/site/logout'], 'post')
        . Html::submitButton(
            'Logout (' . Yii::$app->user->identity->username . ')',
            ['class' => 'btn btn-link', 'id' => "mian_layout_form"]
        )
        . Html::endForm() ?>
</div>
<div id="mian_set_password_modal" class="modal hide fade">
    <div class="modal-body">
        <h4 id="biaoti">修改密码 </h4>

        <div id="mian_set_password_modal_error"></div>
        <form action="#" method="post" class="form-horizontal">
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">新密码:&nbsp;&nbsp;<span style="color: red">*</span></label>

                    <div class="controls">
                        <input class="m-wrap span10" id="zfy_new_password" type="password" value=""/>
                        <span id="role_description"></span>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">重复密码:&nbsp;&nbsp;<span style="color: red">*</span></label>

                    <div class="controls">
                        <input class="m-wrap span10" id="zfy_confim_password" type="password" value=""/>
                        <span id="role_description"></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn">返回</button>
        <button type="button" class="btn green" id="zfy_main_click">修改</button>
    </div>
</div>
<div id="mian_set_info_modal" class="modal hide fade">
    <div class="modal-body">
        <h4 id="biaoti">修改个人信息 </h4>

        <div id="mian_set_info_modal_error"></div>
        <form action="#" method="post" class="form-horizontal">
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">姓名:&nbsp;&nbsp;<span style="color: red">*</span></label>

                    <div class="controls">
                        <input class="m-wrap span10" id="main_zfy_truename" value=""/>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">手机:&nbsp;&nbsp;<span style="color: red">*</span></label>

                    <div class="controls">
                        <input class="m-wrap span10" id="main_zfy_mobile" value=""/>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">性别:&nbsp;&nbsp;<span style="color: red">*</span></label>

                    <div class="controls">
                        <input type="Radio" name="main_zfy_sex" value="1" checked/>
                        男
                        <input type="Radio" name="main_zfy_sex" value="2"/>
                        女
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="control-group">
                    <label class="control-label">部门:&nbsp;&nbsp;</label>

                    <div class="controls">
                        <input class="m-wrap span10" id="main_zfy_position" value=""/>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn" id="zfy_main_info_back">返回</button>
        <button type="button" class="btn green" id="zfy_main_info_click">修改</button>
    </div>
</div>
<div class="footer">
    <div class="footer-inner"> 2015 &copy; 绿城后台管理系统</div>
    <div class="footer-tools"><span class="go-top"> <i class="icon-angle-up"></i> </span></div>
</div>

<script>
    jQuery(document).ready(function () {
        App.init(); // initlayout and core plugins
        Index.init();
        //Index.initJQVMAP(); // init index page's custom scripts
        Index.initCalendar(); // init index page's custom scripts
        Index.initCharts(); // init index page's custom scripts
        Index.initChat();
        Index.initMiniCharts();
        Index.initDashboardDaterange();
        Index.initIntro();
        //FormComponents.init();
    });
</script>

<script type="text/javascript">
    // var _gaq = _gaq || [];
    // _gaq.push(['_setAccount', 'UA-37564768-1']);
    // _gaq.push(['_setDomainName', 'keenthemes.com']);
    // _gaq.push(['_setAllowLinker', true]);
    // _gaq.push(['_trackPageview']);
    // (function() {
    // var ga = document.createElement('script');
    // ga.type = 'text/javascript';
    // ga.async = true;
    // ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
    // var s = document.getElementsByTagName('script')[0];
    // s.parentNode.insertBefore(ga, s);  })();
    function main_layout() {
        $("#mian_layout_form").click();
    }
    function main_set_pwd_zfy() {
        $("#mian_set_password_modal").modal();
        $("#zfy_main_click").click(function () {
            var new_pwd = $("#zfy_new_password").val();
            if (new_pwd.length <= 5 || new_pwd.length >= 20) {
                $("#mian_set_password_modal_error").html("<span style='color: darkred'>密码长度不能太低或者太高</span>");
                return false;
            }
            var confim_pwd = $("#zfy_confim_password").val();
            if (confim_pwd != new_pwd) {
                $("#mian_set_password_modal_error").html("<span style='color: darkred'>两次密码不一致！</span>");
                return false
            }
            $.ajax({
                type: "POST",
                dataType: "json",
                data: {"password": new_pwd},
                url: "<?=Url::to(['rbac/updatemainpassword'])?>",
                success: function (data) {
                    if (data == true) {
                        location.href = "index.php?r=site";
                    } else {
                        $("#mian_set_password_modal_error").html("<span style='color: darkred'>修改失败！</span>");
                    }
                }
            });
        });
    }
    function main_set_info_zfy() {
        $("#mian_set_info_modal_error").empty();
        var id = "<?=Yii::$app->user->id;?>";
        $.ajax({
            type: "POST",
            dataType: "json",
            data: {"id": id},
            url: "<?=Url::to(['rbac/getuser'])?>",
            success: function (data) {
                $("#mian_set_info_modal_error").empty();
                var data = eval(data);
                $("#main_zfy_truename").val(data['truename']);
                $("#main_zfy_mobile").val(data['mobile']);
                $("#main_zfy_position").val(data['position']);
                $("input[name=main_zfy_sex][value='" + data['sex'] + "']").attr('checked', 'true');
                $("#mian_set_info_modal").modal();
                $("#zfy_main_info_click").click(function () {
                    $("#mian_set_info_modal_error").empty();
                    var truename = $("#main_zfy_truename").val();
                    if (truename == '' || truename == null) {
                        $("#mian_set_info_modal_error").append("<p style='color: red'>姓名不能为空</p>");
                        return false;
                    }
                    var mobile = $("#main_zfy_mobile").val();
                    var mobilett = /^1[0-9][0-9]\d{4,8}$/;
                    if (mobile == '' || mobile == null || !mobilett.test(mobile)) {
                        $("#mian_set_info_modal_error").append("<p style='color: red'>手机号码格式不正确</p>");
                        return false;
                    }
                    var position = $("#main_zfy_position").val();
                    var sex = $("input[name=main_zfy_sex]:checked").val();
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        data: {"truename": truename, "mobile": mobile, "position": position, "sex": sex},
                        url: "<?=Url::to(['rbac/edituser'])?>",
                        success: function (data) {
                            if (data == true) {
                                $("#zfy_main_info_back").click();
                            } else {
                                $("#mian_set_info_modal_error").append("<p style='color: red'>更新失败</p>");
                                return false;
                            }
                        }
                    });
                });

            }
        });
    }
</script>

</body>
</html>
